package com.lgy.springboot_example.config;

import com.lgy.springboot_example.utils.DataResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionConfig {

    //全局异常捕获
    @ExceptionHandler(value = Exception.class)
    public DataResult<Object> globalException(Exception e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);//logback记录日志
        return new DataResult<>(-1, "系统错误！！！", e.getMessage());
    }

}
